<?php
/**
 * 帮助中心
 *      [Jsen.net] (C)2013-2099 Jason Group Science and technology co., LTD.
 *      This is NOT a freeware, use is subject to license terms
 *      http://www.jsen.net
 *      tel:400-681-9511
*/
class ApiController extends JasonBaseController{
	public function _initialize() {
        parent::_initialize(); 
		$this->url="http://192.168.1.124/";   
    }
	public function index(){
		for ($x=0; $x<=500; $x++) {
			echo $this->showTime(1464364201+300*$x); 
		}
		exit;	
	}
	public function showTime($time){
		$jx_time = get_bless_time($time);
		echo date("H:i:s",$time).'--揭晓：'.date('Y-m-d H:i:s',$jx_time);
	    $number = get_qishu_number($jx_time);
		echo '----'.$number.'</br>';
		
	}
	//城市列表
    public function getArea(){
	  $parent_id=$_GET["pid"]==""?1:$_GET["pid"];
      $where['parent_id'] =$parent_id;
      $row = M('region')->field("area_id,area_name")->where($where)->select();
      $data["status"]="y";
	  $data["list"]=$row;
	  $this->ajaxReturn($data);
    }
	
	//商品分类
	public function getCategory(){
	  $parent_id=$_GET["pid"]==""?0:$_GET["pid"];
      $row=D('Category')->lists($parent_id,"","id,name");
      $data["status"]="y";
	  $data["list"]=$row;
	  $this->ajaxReturn($data);
    }
	
	//新闻列表
	public function getNewslist(){
	  $category_id=$_GET["pid"]==""?0:$_GET["pid"];
	  $where['category_id'] =$category_id;
	  $limit=$_GET["limit"]==""?10:$_GET["limit"];
      $row=M('article')->field("id,title,category_id,create_time,content")->where($where)->limit($limit)->order("sort desc,id desc")->select();
	  foreach($row as $key=>$val){
		$list[$key]["id"]=$val["id"];
		$list[$key]["title"]=$val["title"];
		$list[$key]["content"]=msubstr(strip_tags($val["content"]),100);
		$list[$key]["create_time"]=date("Y-m-d H:i:s",$val["create_time"]); 
		$list[$key]["category_id"]=$val["category_id"];
		$list[$key]["link_url"]=U("Jason/api/artdetail",array("id"=>$val["id"]));
	  }
      $data["status"]="y";
	  $data["list"]=$list;
	  $this->ajaxReturn($data);
    }
	
	//商品列表
	public function getGoodslist(){
	  $cat_ids=$_GET["pid"]==""?0:$_GET["pid"];
	  $where['cat_ids'] =$cat_ids;
	  $where['status'] =1;
	  $limit=$_GET["limit"]==""?10:$_GET["limit"];
      $row=M('goods')->field(true)->where($where)->limit($limit)->order("sort desc,id desc")->select();
	  foreach($row as $key=>$val){
		$list[$key]["id"]=$val["id"];
		$list[$key]["name"]=$val["title"];
		$list[$key]["list_img"]=$val["list_img"];
		$list[$key]["price"]=$val["min_shop_price"];
		$list[$key]["link_url"]=U("Jason/api/goodsdetail",array("id"=>$val["id"]));
	  }
      $data["status"]="y";
	  $data["list"]=$list;
	  $this->ajaxReturn($data);
    }
	
	//热门搜索
	public function getHotkey(){
	  $hotword = str_replace('，',',',C('site_hotword'));
	  $arr=explode(',', $hotword);
	  foreach($arr as $key=>$val){
		 $list[$key]["name"]=$val; 
	  }
      $data["status"]="y";
	  $data["list"]=$list;
	  $this->ajaxReturn($data);
    }
	
	//联盟商家行业
	public function getUnioncat(){
      $row = M('union_type')->field("id,type_name")->order("id desc")->select();
      $data["status"]="y";
	  $data["list"]=$row;
	  $this->ajaxReturn($data);
    }
	
	//首页Banner
	public function getBanner(){
	  $limit=$_GET["limit"]==""?10:$_GET["limit"];
	  $sqlmap = array();
	  $sqlmap['status'] = 1;
	  $order = (empty($order)) ? '`sort` DESC,`id` DESC' : '';
	  $order='`sort` DESC,`id` DESC';
      $row = M('focus')->field("pic,url")->where($sqlmap)->limit($limit)->order($order)->select();
      $data["status"]="y";
	  $data["list"]=$row;
	  $this->ajaxReturn($data);
    }
	
	//购物车列表
	public function getCartlist(){
	  $sqlmap = array();
	  $sqlmap['user_id'] = 1;
	  $order='`id` DESC';
      $row = M('cart')->field(true)->where($sqlmap)->limit($limit)->order($order)->select();
      $data["status"]="y";
	  $data["list"]=$row;
	  $this->ajaxReturn($data);
    }
	
	
}